package com.kepler.social.generic;

import com.kepler.social.service.vo.LoginUser;
import com.kepler.social.service.vo.SysUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@Slf4j
public class SecurityHelper {

    public static ThreadLocal<LoginUser> loginUserTl = new ThreadLocal<>();

    public static void setLoginUser(LoginUser loginUser){
        loginUserTl.set(loginUser);
    }

    public static LoginUser getLoginUser(){
        return loginUserTl.get();
    }

    public static SysUserVo getSysUserVo() {
        LoginUser loginUser = loginUserTl.get();
        return Objects.nonNull(loginUser) ? loginUser.getUser() : null;
    }

    public static void clearLoginUser(){
        loginUserTl.remove();
    }

}